(function ($) {
  var that;
  $.fn.showData = function showData(option) {
    that = this;
    var e; //用于存储用户定义的事件
    // 配置默认参数
    var def = { url: "default.json" };
    var setting = $.extend({}, def, option);
    // console.log(option);
    // 用Ajax来获取远程数据

    // 遍历用户事件时不能有url，所以要执行删除操作
    delete option.url;
    e = option;
    console.log(e);

    $.ajax({
      type: "get",
      url: setting.url,
      async: "true",
      dataType: "json",
      success: function (data) {
        htmlContent(data);
      },
    });
    
    function htmlContent(data) {
      var txt = "";
      for (var i in data) {
        txt +=
          "<tr>" +
          "<td>" +
          data[i].sno +
          "</td>" +
          "<td>" +
          data[i].sname +
          "</td>" +
          "<td>" +
          data[i].saddr +
          "</td>" +
          "<td>" +
          data[i].stel +
          "</td>" +
          "<td><a href='javascript:void(0)'>删除</a></td>" +
          "</tr>";
      }
      // $("#stus").append(txt);
      // console.log(that); //jQuery.fn.init [tbody#stus]
      that.html(txt);

      // 调用 用户事件
      addEvent();
    }

    // 自定义事件
    function addEvent() {
      $.each(e, function (event, callback) {
        // 父元素Dom.on(事件名，子元素，事件处理函数)  事件委托
        $(that).on(event, "tr", callback);
        // $(that).on(i,"td",v)
      });
    }
    return that;
  };
})(jQuery);
